home *** CD-ROM | disk | FTP | other *** search
- #include <Memory.h>
- #include <ToolUtils.h>
- #include <Dialogs.h>
- #include <Resources.h>
- #include <Events.h>
- #include <Menus.h>
- #include <Fonts.h>
- #include <Scrap.h>
- #include <FixMath.h>
- #include <Desk.h>
- #include <OSEvents.h>
-
- #include "access library.h"
- #include "access menu.h"
- #include "path2pict.h"
-
- enum {
- kAppleMenu = 1, kFileMenu, kEditMenu, kTypeMenu, kStyleMenu, kSpecialMenu
- };
-
- enum {
- kText = 1, kOutline = 3, kOutlinePoints
- };
-
- WindowPtr gWind;
- static Rect stagRect = { 44, 8, 472, 632 };
- static Rect growRect = { 32, 32, 32000, 32000 };
- fontList gList;
- short gTypeItem = 0, gStyleItem = 0, gSpecialItem = kOutline;
- MenuHandle gTypeMenu, gStyleMenu, gSpecialMenu;
-
- FixPoint gScale;
- short gPointSize;
- Str255 gName;
-
- void InitToolbox()
- {
- InitGraf(&qd.thePort); InitFonts(); FlushEvents(0xffff,0);
- InitWindows(); InitMenus(); InitDialogs(0); TEInit(); InitCursor();
-
- gList = BuildFontList();
- }
-
- void Pause(long ticks)
- {
- long target = TickCount() + ticks;
- while (TickCount() < target)
- ;
- }
-
- void Update(int changed)
- {
- Rect r = qd.thePort->portRect;
- short high, wide;
-
- EraseRect(&gWind->portRect);
- InsetRect(&r, 16, 16);
-
- high = r.bottom - r.top;
- wide = r.right - r.left;
-
- TextSize(120);
- TextFont(GetFontFond(gList, gTypeItem, gStyleItem));
- TextFace(GetFontFace(gList, gTypeItem, gStyleItem));
-
- SetOutlinePreferred(true);
- SetPreserveGlyph(true);
- SetFractEnable(true);
-
- { Str255 name;
- Handle sfnt = GetFontStyle(gList, gTypeItem, gStyleItem);
- FontInfo info;
-
-
- GetSfntNameString(sfnt, name_Family, name);
- GetFontInfo(&info);
- { short width = StringWidth(name);
- short height = info.ascent + info.descent;
- Fixed scaler;
-
- if ( (long)high * width > (long)wide * height )
- scaler = FixRatio( wide, width );
- else
- scaler = FixRatio( high, height );
- TextSize(FixMul(qd.thePort->txSize, scaler));
- GetFontInfo(&info);
-
- width = FixMul(scaler, width);
- height = FixMul(scaler, height);
-
- width = r.right - r.left - width;
- height = r.bottom - r.top - height;
- MoveTo( r.left + width/2, r.top + height / 2 + info.ascent );
- if (gSpecialItem == kText)
- DrawString(name);
- else
- { FixPoint scale;
-
- scale.y = scale.x = 0x10000;
- FrameText(name, &scale, gSpecialItem == kOutlinePoints);
-
- gScale = scale;
- gPointSize = qd.thePort->txSize;
- BlockMove(name, gName, name[0] + 1);
- }
- }
- }
-
- SetOutlinePreferred(false);
- SetPreserveGlyph(false);
- SetFractEnable(false);
-
- { Str255 str;
- Handle sfnt = GetFontStyle(gList, gTypeItem, gStyleItem);
- TextFont(1);
- TextFace(0);
- TextSize(9);
- MoveTo(12, 12); DrawString((ConstStr255Param)"\pFull: ");
- GetSfntNameString(sfnt, name_FullName, str);
- MoveTo(76, 12); DrawString(str);
- MoveTo(12, 24); DrawString((ConstStr255Param)"\pUnique: ");
- GetSfntNameString(sfnt, name_UniqueName, str);
- MoveTo(76, 24); DrawString(str);
- MoveTo(12, 36); DrawString((ConstStr255Param)"\pCopyright: ");
- GetSfntNameString(sfnt, name_Copyright, str);
- MoveTo(76, 36); DrawString(str);
- MoveTo(12, 48); DrawString((ConstStr255Param)"\pTrademark: ");
- GetSfntNameString(sfnt, name_Trademark, str);
- MoveTo(76, 48); DrawString(str);
- MoveTo(12, 60); DrawString((ConstStr255Param)"\pVersion: ");
- GetSfntNameString(sfnt, name_Version, str);
- MoveTo(76, 60); DrawString(str);
- }
- }
-
- void SetSpecial(short item)
- {
- gSpecialItem = item;
-
- CheckItem(gSpecialMenu, kText, item == kText);
- CheckItem(gSpecialMenu, kOutline, item == kOutline);
- CheckItem(gSpecialMenu, kOutlinePoints, item == kOutlinePoints);
- }
-
- int SetTypeStyle(short item)
- {
- short count = CountFontStyles(gList, gTypeItem);
-
- if (item > count)
- return false;
-
- gStyleItem = item;
- { short i, face = GetFontFace(gList, gTypeItem, item);
- short faceItem = count + 2;
-
- for (i = 1; i <= count; i++)
- CheckItem(gStyleMenu, i, i == item);
- for (i = faceItem; i < faceItem + 7; i++)
- CheckItem(gStyleMenu, i, false);
- while (face)
- { if (face & 1)
- CheckItem(gStyleMenu, faceItem, true);
- faceItem++;
- face >>= 1;
- }
- }
- return true;
- }
-
- int SetTypeFace(short menuItem)
- {
- { Str255 name;
- GetItem(gTypeMenu, menuItem, name);
- gTypeItem = FindFamilyIndex(gList, name);
- if (gTypeItem == 0)
- gTypeItem = 1;
- }
-
- { short i, count = CountMItems(gTypeMenu);
- for (i = 1; i <= count; i++)
- CheckItem(gTypeMenu, i, menuItem == i);
- }
-
- DeleteMenu(kStyleMenu);
- DisposeMenu(gStyleMenu);
- InsertMenu(gStyleMenu = NewMenu(kStyleMenu, (ConstStr255Param)"\pStyle"), kSpecialMenu);
-
- { short i, count = CountFontStyles(gList, gTypeItem);
- for (i = 1; i <= count; i++)
- AppendMenu(gStyleMenu, (ConstStr255Param)"\pstyle");
- AppendMenu(gStyleMenu, (ConstStr255Param)"\p(-;(Smear<B;(Slant<I;(Underline<U;(Outline<O;(Shadow<S;(Condense;(Extend");
- SetItemStyle(gStyleMenu, count + 7, condense);
- SetItemStyle(gStyleMenu, count + 8, extend);
-
- for (i = 1; i <= count; i++)
- { Str255 name;
- Handle sfnt = GetFontStyle(gList, gTypeItem, i);
- GetSfntNameString(sfnt, name_Subfamily, name);
- SetItem(gStyleMenu, i, name);
- }
- }
- SetTypeStyle(1);
-
- return true;
- }
-
- void MakeTypeMenu(MenuHandle menu)
- {
- short i, count = CountFontFamilies(gList);
-
- for (i = 1; i <= count; i++)
- { Str255 name;
- Handle sfnt = GetFontStyle(gList, i, 1);
- GetSfntNameString(sfnt, name_Family, name);
- AppendMenu(menu, name);
- }
- SortMenu(menu); /**/
- SetTypeFace(1);
- }
-
- void MakeMenus()
- {
- char s[2];
- MenuHandle aMenu;
-
- s[0] = 1; s[1] = appleMark;
- InsertMenu(aMenu = NewMenu(kAppleMenu, (ConstStr255Param)s), 0);
- AppendMenu(aMenu, (ConstStr255Param)"\pAbout last night…;(-");
- AddResMenu(aMenu, 'DRVR');
- InsertMenu(aMenu = NewMenu(kFileMenu, (ConstStr255Param)"\pFile"), 0);
- AppendMenu(aMenu, (ConstStr255Param)"\pQuit/Q");
- InsertMenu(aMenu = NewMenu(kEditMenu, (ConstStr255Param)"\pEdit"), 0);
- AppendMenu(aMenu, (ConstStr255Param)"\p(Undo/Z;(-;(Cut/X;Copy/C;(Paste/V;(Clear");
- InsertMenu(gTypeMenu = NewMenu(kTypeMenu, (ConstStr255Param)"\pType"), 0);
- MakeTypeMenu(gTypeMenu);
- InsertMenu(gStyleMenu = NewMenu(kStyleMenu, (ConstStr255Param)"\pStyle"), 0);
- InsertMenu(gSpecialMenu = NewMenu(kSpecialMenu, (ConstStr255Param)"\pSpecial"), 0);
- AppendMenu(gSpecialMenu, (ConstStr255Param)"\pText;(-;Outline;Outline+");
- SetSpecial(gSpecialItem);
- DrawMenuBar();
- HiliteMenu(0);
- }
-
- void CreatePict()
- {
- Rect myRect;
- PicHandle myPicHandle;
- paths* text;
- RgnHandle saveClip = NewRgn();
-
- TextSize(gPointSize);
- TextFont(GetFontFond(gList, gTypeItem, gStyleItem));
- TextFace(GetFontFace(gList, gTypeItem, gStyleItem));
-
- text = Text2Paths(gName, &gScale, 0);
- GetPathsBounds(text, &myRect);
- myRect.right += qd.thePort->pnSize.h;
- myRect.bottom += qd.thePort->pnSize.v;
-
- /* Make room for the point handles
- */
- if (gSpecialItem == kOutlinePoints)
- InsetRect(&myRect, -3, -3);
-
- GetClip( saveClip );
-
- myPicHandle = OpenPicture( &myRect );
- ClipRect( &myRect );
- if (gSpecialItem != kText )
- AddPathsToPict( text );
- if (gSpecialItem == kOutlinePoints)
- MarkPaths( text );
- ClosePicture();
-
- SetClip( saveClip );
- DisposeRgn( saveClip );
-
- DisposePaths(text);
-
- ZeroScrap();
- HLock( (Handle)myPicHandle );
- PutScrap( GetHandleSize((Handle)myPicHandle), 'PICT', (Ptr)*myPicHandle );
- HUnlock( (Handle)myPicHandle );
- UnloadScrap();
-
- KillPicture( myPicHandle );
- }
-
-
- int DoMenu(long cmd)
- {
- short menu = HiWord(cmd);
- short item = LoWord(cmd);
-
- switch (menu)
- { case kFileMenu:
- return true;
- case kEditMenu:
- if (item == 4)
- CreatePict();
- break;
- case kTypeMenu:
- if (SetTypeFace(item))
- Update(true);
- break;
- case kStyleMenu:
- if (SetTypeStyle(item))
- Update(true);
- break;
- case kSpecialMenu:
- SetSpecial(item);
- Update(true);
- break;
- }
-
- HiliteMenu(0);
- return false;
- }
-
- void DoMouse(Point p)
- {
- }
-
-
- int EventLoop()
- {
- EventRecord theEvent;
- WindowPtr whichWindow;
-
- SystemTask();
- if (!GetNextEvent(everyEvent, &theEvent))
- return false;
-
- switch(theEvent.what)
- {
- case mouseDown:
- switch (FindWindow(theEvent.where, &whichWindow))
- { case inSysWindow:
- SystemClick(&theEvent, whichWindow);
- break;
- case inMenuBar:
- return DoMenu(MenuSelect(theEvent.where));
- break;
- case inDrag:
- DragWindow(whichWindow, theEvent.where, &qd.screenBits.bounds);
- break;
- case inGoAway:
- if (TrackGoAway(whichWindow, theEvent.where))
- return true;
- break;
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- else if (whichWindow == gWind)
- { Point p = theEvent.where;
-
- GlobalToLocal(&p);
- DoMouse(p);
- }
- break;
- case inGrow:
- { long newSize;
- DrawGrowIcon(whichWindow);
- newSize = GrowWindow(whichWindow, theEvent.where, &growRect);
- SizeWindow(whichWindow, LoWord(newSize), HiWord(newSize), true);
- SetPort(whichWindow);
- InvalRect(&whichWindow->portRect);
- }
- break;
- }
- break;
-
- case keyDown:
- break;
-
- case updateEvt:
- BeginUpdate((WindowPtr)theEvent.message);
- Update(false);
- EndUpdate((WindowPtr)theEvent.message);
- break;
- }
- return false;
- }
-
- main()
- {
- long count, i;
- Handle sfnt;
-
- InitToolbox();
-
- MakeMenus();
-
- SetPort(gWind = NewCWindow(0,&stagRect,(ConstStr255Param)"\pUntitled",true,0,(WindowPtr)-1,true,0));
-
- while (!EventLoop())
- ;
- }
-
-